<?php

/**
 * This file is part of the Pagizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Pagizer Core Team <team@pagizer.org>
 * @package     pagizer
 * @subpackage  website
 */

class m_website_documents_FreeContent extends m_website_documents_FreeContentBase
{
	/**
	 * @return m_website_documents_FreeContent
	 */
	public static function createNew()
	{
		return new self();
	}
	
	/**
	 * @return m_website_documents_FreeContent
	 */
	public static function getInstanceByUniqueId($id, $lang = null)
	{
		if(is_null($lang)) $lang = f_core_Context::getInstance()->getLang();
		$cache = f_core_Cache::getInstance();
		
		$key = $cache->getDocumentCacheKey($id, $lang);
		
		if($cache->hasCache($key))
		{
			return $cache->getCacheContent($key);
		}
		
		$object = new self($id, $lang);
		
		$cache->putInCache($key, $object);
		
		return $object;
	}
	
	public function postSave()
    {
        $tpl = f_template_Template::getInstance();

        $tpl->setModuleTemplate("website", "front/block/FreeContent.html");
        $tpl->addCacheDiscriminator($this->getUniqueId(), $this->getLang()."|content|free");

        $tpl->clearTemplateCache();
    }

    public function postDelete()
    {
        $tpl = f_template_Template::getInstance();

        $tpl->setModuleTemplate("website", "front/block/FreeContent.html");
        $tpl->addCacheDiscriminator($this->getUniqueId(), $this->getLang()."|content|free");

        $tpl->clearTemplateCache();
    }
}